package field

import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/astaxie/beego/orm"
)

type JsonList []string
//String() string
//FieldType() int
//SetRaw(interface{}) error
//RawValue() interface{}
func(t *JsonList) String() string {
	return fmt.Sprintf("%v",*t)
}
func (t *JsonList) FieldType() int {
	return orm.TypeTextField
}

// SetRaw 读取数据库值
func(t *JsonList) SetRaw(value interface{}) error{
	switch value.(type){
	case string:
		err := json.Unmarshal([]byte(value.(string)),t)
		if err!=nil{
			return err
		}
		return nil
	}
	return errors.New("JsonList读取失败")
}
//写入数据库
func(t *JsonList)RawValue() interface{} {
	bs,err:=json.Marshal(*t)
	if err!=nil{
		return ""
	}
	return string(bs)
}
